package set;

import java.util.ArrayList;

import linkedList.CandyLinkedList;
import util.FileOperation;

public class CandyLinkedListSet<E> implements set.CandySet<E> {
    private CandyLinkedList<E> list;
    
    public CandyLinkedListSet() {
        list = new CandyLinkedList<>();
    }

    @Override
    public void add(E e) {
        if(!list.contains(e)) {
            list.addLast(e);
        }
    }

    @Override
    public void remove(E e) {
        list.removeElement(e);
    }

    @Override
    public boolean contains(E e) {
        return list.contains(e);
    }

    @Override
    public int getSize() {
        return list.getSize();
    }

    @Override
    public boolean isEmpty() {
        return list.isEmpty();
    }
    
    public static void main(String[] args) {
        wordCount("傲慢与偏见英文原版书词汇量统计：", "testData/pride-and-prejudice.txt");
        wordCount("双城记原版书词汇量统计：", "testData/a-tale-of-two-cities.txt");
    }
    
    // 统计词汇量
    private static void wordCount(String title, String filePath) {
        System.out.println("-------------" + title + "----------------");
        ArrayList<String> words1 = new ArrayList<>();
        FileOperation.readFile(filePath, words1);
        System.out.println("数量总数：" + words1.size());
        CandyLinkedListSet<String> set = new CandyLinkedListSet<>();
        for(String word : words1) {
            set.add(word);
        }
        System.out.println("不同单词数量：" + set.getSize());
    }
}
